//
// See the file COPYING for redistribution information.
//

#include <iostream>
#include <fstream>
#include <Naipax.hpp>

using namespace std;
using namespace Naipax;

int main() {
    cerr << "Test for the LinkExtor module" << endl;

    try {
        string HtmlStr;
        fstream HtmlFs;

        HtmlFs.open("LinkExtor.html", ifstream::in);
        if (HtmlFs.is_open() == true) {
            char Buf[1024];
            while (HtmlFs.getline(Buf, 1024)) {
                HtmlStr += Buf;
            }
            HtmlFs.close();
        }
        else {
            NAIPAX_PERROR("Cannot open file");
            return -1;
        }

        LinkExtor LE;
        vector<string> UrlList;

        LE.BaseUrl() = "http://yahoo.com";
        cout << "Base URL: " << LE.BaseUrl() << endl;

        LE.DiscardPattern() = "digg";
        cout << "Discard pattern: " << LE.DiscardPattern() << endl;

        LE.Extract(HtmlStr, UrlList);
        for (vector<string>::iterator it = UrlList.begin();
             it != UrlList.end(); it++) {
            cout << " - " << *it << endl;
        }

    }
    catch (Naipax::Error &E) {
        NAIPAX_PERROR(E.What());
        return -1;
    }

    return 0;
}
